<template>
    <div>
        <h1>科室添加</h1>
        <table class="table table-bordered">
           <tbody>
             <tr>
                <td align="right">药品名称</td>
                <td><input type="text" v-model="info.drugName"></td>
            </tr>
            <tr>
                <td align="right">科室名称</td>
                <td><input type="text" v-model="info.departmentId"></td>
            </tr>
            <tr>
                <td align="right">用药日期</td>
                <td><input type="date" v-model="info.drugTime"></td>
            </tr>
            <tr>
                <td align="right">病人名称</td>
                <td><input type="text" v-model="info.people"></td>
            </tr>
            <tr>
                <td align="right">病房号码</td>
                <td><input type="text" v-model="info.drugHouse"></td>
            </tr>
            <tr>
                <td align="right">用药状态</td>
                <td><input type="radio" v-model="info.drugState" :value="1" name="states">完成
                <input type="radio" v-model="info.drugState" :value="0" name="states">未完成</td>
            </tr>
            <tr>
                <td align="right">配药医生</td>
                <td><input type="text" v-model="info.drugPeople"></td>
            </tr>
            <tr>
                <td align="right"></td>
                <td><input type="button" value="提交" @click="add"></td>
            </tr>
           </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import {ref,reactive,onMounted} from "vue";
import axios from "axios";
import moment from "moment";
import {useRouter,useRoute} from "vue-router";
const router=useRouter();
const route=useRoute();
onMounted(()=>
{
    detail();
})
let info:any=reactive({
  "id": route.query.id,
  "drugName": "",
  "departmentId":"",
  "drugTime": "",
  "people": "",
  "drugHouse": "",
  "drugState": "",
  "drugPeople": "",
})
const add=()=>
{
    
    axios({
        url:'http://localhost:5182/api/Money/UpdDrug',
        method:'put',
        data:info
    })
    .then((res)=>
    {
        console.log(res);
        if(res.data>0)
        {
            alert("修改成功");
            router.push('/showdrug')
            return;
        }
        else
        {
            alert("修改失败");
            return;
        }
    })
    .catch((err)=>
    {
        console.log(err);
    })
}

const detail=()=>
{
    axios({
        url:'http://localhost:5182/api/Money/Dateil',
        method:'get',
        params:{
            id:route.query.id
        }
    })
    .then((res)=>
    {
        console.log(res);
        Object.assign(info,res.data);
        info.drugTime=res.data.drugTime.substring(0,10);
    })
    .catch((err)=>
    {
        console.log(err);
    })
}
</script>

<style scoped>

</style>